<template>
  <div class="pickingList">
    <div class="publicSearch">
      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button
            @click="getpickingListData"
            size="mini"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh"
            >重置</el-button
          >
        </el-button-group>
        <div>
          <span>出库任务号</span>
          <el-input
            v-model="searchData.billNo"
            size="mini"
            placeholder="出库任务号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>拣货任务号</span>
          <el-input
            v-model="searchData.pickTaskCode"
            size="mini"
            placeholder="拣货任务号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>物料编码</span>
          <el-input
            v-model="searchData.itemCode"
            size="mini"
            placeholder="请输入物料编码"
            clearable
          ></el-input>
        </div>
        <div>
          <span>物料名称</span>
          <el-input
            v-model="searchData.itemName"
            size="mini"
            placeholder="请输入物料名称"
            clearable
          ></el-input>
        </div>
        <div>
          <span>批次号</span>
          <el-input
            v-model="searchData.batchName"
            size="mini"
            placeholder="请输入批次号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>追踪号</span>
          <el-input
            v-model="searchData.boxCode"
            size="mini"
            placeholder="请输入追踪号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>库位</span>
          <el-input
            v-model="searchData.cellCode"
            size="mini"
            placeholder="请输入库位"
            clearable
          ></el-input>
        </div>
      </div>
    </div>
    <div class="headerBtns">
      <el-button size="small" type="success" round  @click="sendToYF()" > 传送条码
      </el-button>
    </div>
    <div class="tableBox none">
      <el-table
        v-loading="loading.masterTable"
        highlight-current-row
        :data="pickingLists"
        style="width: 100%"
        :row-style="Mystyle"
        @selection-change="handleSelectionChange"
      >
      <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column fixed="left" type="index" width="50"></el-table-column>
        <el-table-column
          sortable
          fixed="left"
          show-overflow-tooltip
          prop="pickTaskCode"
          label="拣货任务号"
          min-width="160"
        >
        </el-table-column>
        <el-table-column
          sortable
          fixed="left"
          show-overflow-tooltip
          prop="soMasterCode"
          label="出库任务号"
          min-width="120"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="billNo"
          label="单据信息"
          min-width="160"
        >
          <template slot-scope="scope">
            <span>货主: </span>
            <span
              class="textBtn"
              @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.organizationId,
                  'organization'
                )
              "
              >{{ scope.row.organizationName }}</span
            >
            <!-- <br>
            <span>发运单号: </span>
            <span class="textBtn" @click="$router.push({name: 'soBillDetail',params: scope.row})">{{scope.row.billNo}}</span> -->
            <!-- <br>
            <span>客户: </span>
            <span class="textBtn" @click="$parent.showPublicModal(scope.row.customerId, 'customer')">{{scope.row.customerName}}</span> -->
            <br />
            <span>仓库: </span>
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.wareId, 'ware')
              "
              >{{ scope.row.wareName }}</span
            >
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="itemCode"
          label="物料"
          min-width="150"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.itemCode }}</span>
            <br />
            <span>{{ scope.row.itemName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="boxCode"
          label="追踪号"
          min-width="150"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="cellCode"
          label="来源库位"
          width="180"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="toCellCode"
          label="目标库位"
          width="180"
        ></el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="batchName"
          label="批次号"
          min-width="160"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="pickQuantity"
          label="计划数量"
          min-width="90"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="reviewQuantity"
          label="拣货数量"
          min-width="90"
        ></el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="pickTime"
          label="拣货时间"
          min-width="150"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="pickUserName"
          label="拣货人"
          min-width="150"
        ></el-table-column>
      </el-table>
      <el-pagination
        style="text-align: right"
        class="pagination-bottom"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        :page-sizes="[10, 50, 200, 500]"
        :current-page.sync="searchData.pageNum"
        :page-size="searchData.pageSize"
        layout="sizes,total, prev, pager, next"
        :total="searchData.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "pickingList",
  data() {
    // 校验规则
    return {
      isMoreSearch: false,
      loading: {
        masterTable: true,
      },
      multipleSelection: [],
      // 用作查询的数据
      searchData: {
        // 仓库编码 获得当前仓库的编码
        wareId: PF.getLocal("wareId", "number"),
        pageNum: 1,
        pageSize: 10,
        total: null,
        // findBySoMasterId: null,
        billNo: "",
        organizationId: "",
        itemCode: "",
        itemName: "",
        states: "2", // 默认已拣货
        batchName: "",
        areaCode: "",
        shelfCode: "",
        cellCode: "",
        boxCode: "",
        pickTaskCode: ""
      },
      searchStates: [
        {
          value: "enable",
          label: "启用",
        },
        {
          value: "disable",
          label: "禁用",
        },
      ],
      //存放装箱单数据的数组
      pickingLists: [],
      form: {
        //
      },
      rules: {
        //
      },
      formLabelWidth: "120px",
      rowData: {
        //
      },
      Mystyle: { height: "50px" },
      filterText: "",
      defaultProps: {
        children: "children",
        label: "name",
      },
      roleRowInfo: {
        //
      },
      roleForm: {
        //
      },
      roleRules: {
        //
      },
      tableRowClassName({ row, rowIndex }) {
        if (row.accountStatus === "disable") {
          return "disable-row";
        } else if (row.accountStatus === "enable") {
          return "enable-row";
        }
        return "";
      },
    };
  },
  computed: {},
  watch: {
    //
  },
  methods: {
    //分页设置每页的条数
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getpickingListData();
    },
    //分页设置从第几条开始
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getpickingListData();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 清空查询出库任务号
    clearSearchData() {
      this.searchData.keyWords = "";
      this.searchData.billNo = "";
      this.searchData.organizationId = "";
      this.searchData.itemCode = "";
      this.searchData.itemName = "";
      this.searchData.state = "";
      this.searchData.source = "";
      this.searchData.areaCode = "";
      this.searchData.shelfCode = "";
      this.searchData.cellCode = "";
      this.searchData.batchName = "";
      this.searchData.pickTaskCode = "";
      this.searchData.boxCode = "";
    },
    //根据筛选条件查询数据
    getpickingListData() {
      let that = this;
      that.loading.masterTable = true;
      let searchData = JSON.parse(JSON.stringify(this.searchData));

      IOT.getServerData("/pick/tasks/list", "get", searchData, (ret) => {
        that.loading.masterTable = false;
        if (ret.code === 200) {
          // rows就是返回的数据
          this.pickingLists = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    sendToYF() {
      let that = this;
      IOT.showOverlay("保存中，请稍等...");
      let form = [];
      form = PF.JSON(this.multipleSelection);
      let ids = [];
      for (let i = 0; i < form.length; i++) {
        ids.push(form[i].pickTaskId);
      }
      IOT.getServerData(
        "/pick/tasks/sentToYf",
        "post",
        { ids: ids },
        (ret) => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("传递成功！", "success", 1000, () => {
              that.getpickingListData();
            });
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    // // 进行删除
    // isDelete(id) {
    //   this.$confirm("确认删除？")
    //     .then(_ => {
    //       this.delete(id);
    //     })
    //     .catch(_ => {});
    // },
    // // 根据主键id删除
    // delete(id) {
    //   let that = this;
    //   IOT.showOverlay("删除中，请稍等...");
    //   IOT.getServerData("/pickingList/deleteById", "get", { id: id }, ret => {
    //     IOT.hideOverlay();
    //     if (ret.code === 200) {
    //       IOT.tips("删除成功！", "success", 1000, () => {
    //         that.getpickingListData();
    //       });
    //     } else {
    //       IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
    //     }
    //   });
    // },
  },
  // 页面加载时刷新
  created() {
    this.getpickingListData();
  },
};
</script>

<style scoped lang="less">
.pickingList {
}
</style>
